<template>
	<el-form ref="ruleFormRef" label-position="top" :model="formInline" :rules="formRules" label-width="auto"
		v-loading="isLoading">
		<el-row :gutter="30">
			<re-col :value='12' :xs='24' :sm='24'>
				<el-form-item :label='titles?.alarmTitle' prop='alarmTitle'>
					<el-input :maxlength="30" :show-word-limit="true" v-model.trim='formInline.alarmTitle' clearable :placeholder='prompt?.alarmTitle' />
				</el-form-item>
			</re-col>
			<re-col :value='12' :xs='24' :sm='24'>
				<el-form-item :label='titles?.alarmAlias' prop='alarmAlias'>
					<el-input :maxlength="30" :show-word-limit="true" v-model.trim='formInline.alarmAlias' clearable :placeholder='prompt?.alarmAlias'
						:formatter="(value) => value.replace(NAME_REG.inputFormat, '')"
						:parser="(value) => value.replace(NAME_REG.inputFormat, '')" />
				</el-form-item>
			</re-col>
			<re-col :value='12' :xs='24' :sm='24'>
				<el-form-item :label='titles?.alarmType' prop='alarmType'>
					<el-select v-model='formInline.alarmType' clearable :placeholder='prompt?.alarmType'
						:style="{ width: '100%' }">
						<el-option v-for="item in ALARM_EVENT_TYPE" :key="item.value" :label="item.label"
							:value="item.value" />
					</el-select>
				</el-form-item>
			</re-col>
			<re-col :value='12' :xs='24' :sm='24'>
				<el-form-item :label='titles?.alarmLevel' prop='alarmLevel'>
					<el-select v-model='formInline.alarmLevel' clearable :placeholder='prompt?.alarmLevel'
						:style="{ width: '100%' }">
						<el-option v-for="item in ALARM_EVENT_LEVEL" :key="item.value" :label="item.label"
							:value="item.value" />
					</el-select>
				</el-form-item>
			</re-col>
			<re-col :value='24' :xs='24' :sm='24'>
				<el-form-item :label='titles?.alarmDesc' prop='alarmDesc'>
					<el-input :maxlength="100" :show-word-limit="true" v-model='formInline.alarmDesc' :autosize="{ minRows: 4 }" type="textarea" clearable
						:placeholder='prompt?.alarmDesc' />
				</el-form-item>
			</re-col>
		</el-row>
	</el-form>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import ReCol from "@/components/ReCol";
import type { FormRules } from "element-plus";
import { titles, prompt } from './index';
import type { infoType } from '@/api/manage/product-management/product-type/alarm-event/index';
import { ALARM_EVENT_TYPE, ALARM_EVENT_LEVEL } from '@/constant/product-management'
import { NAME_REG } from '@/constant/index'
type FormProps = {
	formInline: infoType,
	isLoading: boolean
}

const props = withDefaults(defineProps<FormProps>(), {
	formInline: () => ({} as infoType),
	isLoading: false
});

const formRules = reactive(<FormRules>{
	id: [{ required: true, message: prompt?.id, trigger: 'blur' },],
	alarmTitle: [{ required: true, message: prompt?.alarmTitle, trigger: 'blur' },],
	alarmAlias: [
		{ required: true, message: prompt?.alarmAlias, trigger: 'blur' },
		{ pattern: NAME_REG.role, message: NAME_REG.text, trigger: 'blur' },
	],
	alarmLevel: [{ required: true, message: prompt?.alarmLevel, trigger: 'blur' },],
	alarmType: [{ required: true, message: prompt?.alarmType, trigger: 'blur' },],
	alarmDesc: [{ required: true, message: prompt?.alarmDesc, trigger: 'blur' },],
});
const ruleFormRef = ref();
//    const newFormInline = ref(props.formInline as any);
//
//
//    watch(()=>props.formInline,()=>{
//    	newFormInline.value = props.formInline
//    },{
//    	deep:true,
//    	immediate:true
//    })
function getRef() {
	return ruleFormRef.value;
}

defineExpose({ getRef });
</script>
